var Setup = require("../models/setup");
//系统参数
exports.setupsys = function(req, res) {
	Setup.findOne({"_id":"sys"}, function (err, _sys) {
		res.render('admin/setup-sys', {
			title: '系统参数',
			_sys: _sys
		})
	});
}
//SEO设置
exports.setupseo = function(req, res) {
	res.render('admin/setup-seo', {
		title: 'SEO设置'
	})
}

//修改密码
exports.setuppassword = function(req, res) {
	var admin = req.session.admin;
	res.render('admin/setup-password', {
		title: '修改密码',
		admin:admin
	})
}


//系统参数提交
exports.sysSave = function (req, res) {
	var _sys_ = req.body;
	var sys = {
		sys_basehost: _sys_.sys_basehost,
		sys_weixin: _sys_.sys_weixin,
		sys_weibo: _sys_.sys_weibo,
		sys_qq: _sys_.sys_qq,
		sys_webname: _sys_.sys_webname,
		sys_tel: _sys_.sys_tel,
		sys_phone:_sys_.sys_phone,
		sys_address:_sys_.sys_address,
		sys_keywords:_sys_.sys_keywords,
		sys_description:_sys_.sys_description,

	}

	if (_sys_._id) {
		var id = _sys_._id;
		Setup.update({
			_id: id
		}, sys, function (err) {
			res.redirect("/admin/setupsys");
		});
	} else {
		Setup.create(sys, function (err) {
			res.redirect("/admin/setupsys");
		});
	}

}
